<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>企业注册</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Access-Control-Allow-Origin" content="*">
  <meta name="viewport"
    content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" href="./css/font.css">
  <link rel="stylesheet" href="./css/xadmin.css">
  <link rel="stylesheet" href="./css/w_main.css">
  <link rel="stylesheet" href="./css/login.css">
  <!--[if lt IE 9]>
      <script src="./lib/ie9/html5.min.js"></script>
      <script src="./lib/ie9/respond.min.js"></script>
    <![endif]-->
  <style type="text/css">
    #senContW {
      width: 500px;
      margin-right: auto;
      margin-left: auto;
    }

    #senContW .layui-input {
      width: 280px;
    }

    .senFormW .xg-texearea {
      width: 300px;
    }

    .comText,
    .senFormW .layui-upload-choose {
      color: #fff;
    }

    #yzBtn {
      vertical-align: 0px;
    }
  </style>
</head>

<body class="">
  <div class="x-body">
    <div class="layui-row">
      <!-- 标题 -->
      <div class="reTitle clearfix">
        <span class="btn spanActive">企业信息注册</span>
        <span class="btn">政府信息注册</span>
      </div>
      <!-- 企业信息注册 -->
      <form class="layui-form senFormW" id="senContW">
        <div class="layui-input-block">
          <label class="layui-input-inline comText">公司名称：</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input layui-input-inline" id="CompanyName" />
          </div>
        </div>
        <div class="layui-input-block">
          <label class="layui-input-inline comText">绑定邮箱：</label>
          <div class="layui-input-inline">
            <input class="layui-input layui-input-inline" placeholder="" id="Contact">
          </div>
        </div>
        <!-- <div class="layui-input-block">
             <label class="layui-input-inline comText">手机号：</label>
             <div class="layui-input-inline">
                <input type="number" class="layui-input layui-input-inline" placeholder=""  id="phone" onkeyup="if(this.value.length>11){this.value = this.value.slice(0,11);}" >
                <a href="javascript:;" class="layui-btn layui-input-inline" id="yzBtn">获取验证码</a>
             </div>
           </div>
           <div class="layui-input-block">
             <label class="layui-input-inline comText">账号：</label>
             <div class="layui-input-inline">
                <input type="text" class="layui-input layui-input-inline" placeholder="" name="" id="account">
             </div>
           </div>
           <div class="layui-input-block">
             <label class="layui-input-inline comText">验证码：</label>
             <div class="layui-input-inline">
               <input type="text" class="layui-input layui-input-inline" placeholder="" name="" id="yzCode">
             </div>
           </div>   -->
        <!-- <div class="layui-input-block">
             <label class="layui-input-inline comText">密码：</label>
             <div class="layui-input-inline">
               <input type="password" class="layui-input layui-input-inline" placeholder="" name="" id="Password">
             </div>
           </div>    
           <div class="layui-input-block">
             <label class="layui-input-inline comText">确认密码：</label>
             <div class="layui-input-inline">
                <input type="password" class="layui-input layui-input-inline" placeholder="" name="" id="rePassword">
             </div>
           </div>  -->
        <!-- <div class="layui-input-block">
             <label class="layui-input-inline comText">公司地址：</label>
             <div class="layui-input-inline">
               <textarea class="xg-texearea" id="Address"></textarea>
             </div>
           </div>   -->
        <div class="layui-input-block">
          <label class="layui-input-inline comText">营业执照：</label>
          <div class="layui-input-inline">
            <button type="button" class="layui-btn" id="License">
              <i class="layui-icon"></i>上传文件
            </button>
          </div>
        </div>
        <div class="layui-input-block">
          <label class="layui-input-inline comText">企业资质：</label>
          <div class="layui-input-inline">
            <button type="button" class="layui-btn" id="Entrust">
              <i class="layui-icon"></i>上传文件
            </button>
          </div>
        </div>
        <!-- <div class="layui-input-block">
          <label class="layui-input-inline comText">招聘简章：</label>
          <div class="layui-input-inline">
            <button type="button" class="layui-btn" id="Constitution">
              <i class="layui-icon"></i>上传文件
            </button>

          </div>
        </div> -->
        <div class="layui-input-block">
          <a href="javascript:;" class="layui-btn" id="applyBtn">提交</a>
        </div>
      </form>
    </div>
  </div>
  <script type="text/javascript" src="./js/jquery.min.js"></script>
  <script type="text/javascript" src="./lib/layui/layui.js"></script>
  <script type="text/javascript" src="js/register.js"></script>
  <script type="text/javascript">

    layui.use(['laydate', 'upload'], function () {
      $ = layui.jquery;
      var laydate = layui.laydate;
      var upload = layui.upload;
      var User = store.fetch('user');
      var iNum = 60;
      var Timer = null;
      var phoneOn = true; // 判断手机号是否已经注册
      var accountOn = true; // 判断账号是否已经注册

      var yunyin = comUpload('License');
      var weituo = comUpload('Entrust');
      var zpjz = comUpload('Constitution');


      function comUpload(obj) {
        //var dfd = $.Deferred();
        var objUp = upload.render({
          elem: '#' + obj,//绑定元素
          url: App.url, //上传接口
          method: 'post',
          data: {
            Command: "UploadFile",
            AppId: App.appId,
            Time: new Date().toISOString()
          },
          accept: 'file',
          acceptMime: '',
          multiple: true,
          //auto:false,
          // bindAction:'#applyBtn',
          done: function (res) {
            this.fileUrl = res.File1;
            this.State = true;
            layer.msg('上传成功');
            //dfd.resolve(res);
          },
          error: function (res) {
            this.State = false;
            layer.msg('上传失败');
          }
        });
        return objUp;
      }

      //填写手机号 检测是否存在
      $('#phone').blur(function () {
        yzAccount('#phone').done(function (res) {
          if (res.IsExist == 0) {
            phoneOn = true;
          }
        }).fail(function (res) {
          layer.msg('手机号码已存在');
          phoneOn = false;
        });
      });
      //检测账户
      $('#account').blur(function () {
        yzAccount('#account').done(function (res) {
          if (res.IsExist == 0) {
            accountOn = true;
          }
        }).fail(function (res) {
          layer.msg('账户已存在');
          accountOn = false;
        });
      });
      //倒计时
      $('#yzBtn').click(function () {
        var phoneVal = $.trim($('#phone').val());
        clearInterval(Timer);
        if (phoneVal == '') {
          layer.msg('请输入手机号码');
          return false;
        } else if (!/^((\+86)|(86)|\(86\)|(\+86\)))?(((13[0-9])|(15[0-9])|145|147|(17[0,1,3,5,6,7,8])|18[0-9])\d{8}$)/.test(phoneVal)) {
          layer.msg('手机号不正确');
          return false;
        }
        else {

          var yzData = {
            Command: 'GetVerificationCode',
            Phone: $.trim($('#phone').val())
          }

          if (phoneOn) { //手机号码不存在才发送
            daoTime(60);
          } else {
            layer.msg('手机号码已存在');
            return false;
          }

          //
          if ($(this).html() == '获取验证码' && phoneOn) {
            reAjax(yzData, function (res) {
              if (res.code == 0) {
                layer.msg('发送成功');
              } else {
                layer.msg(res.msg);
              }
            });

          }




        }
      });
      $('#applyBtn').click(function () {
        yState = yunyin.config.State;
        wState = weituo.config.State;
        zState = zpjz.config.State;
        var psw = $.trim($('#Password').val());
        var rePsw = $.trim($('#rePassword').val());
        var phoneVal = $.trim($('#phone').val());
        if (phoneVal == '') {
          layer.msg('手机号不能为空');
          return false;
        }

        if (!/^((\+86)|(86)|\(86\)|(\+86\)))?(((13[0-9])|(15[0-9])|145|147|(17[0,1,3,5,6,7,8])|18[0-9])\d{8}$)/.test(phoneVal)) {
          layer.msg('手机号不正确');
          return false;
        }
        if (!phoneOn) {
          layer.msg('手机号已存在');
          return false;
        }
        if (!accountOn) {
          layer.msg('账号已存在');
          return false;
        }
        if (rePsw !== psw) {
          layer.msg('两次密码输入不一致');
          return false;
        }
        if (!yState) {
          layer.msg('请上传运营执照');
          return false;
        }
        if (!wState) {
          layer.msg('请上传委托书');
          return false;
        }
        if (!zState) {
          layer.msg('请上传招聘简章');
          return false;
        }




        var regData = {
          Command: 'RegisterCompany',
          CompanyName: $('#CompanyName').val(),
          Contact: $('#Contact').val(),
          CompanyName: $('#CompanyName').val(),
          ContactPhone: $('#phone').val(),
          Address: $('#Address').val(),
          Verification: $('#yzCode').val(),
          Password: psw,
          UserName_c: $('#account').val(),
          Constitution: zpjz.config.fileUrl,
          Entrust: weituo.config.fileUrl,
          License: yunyin.config.fileUrl
        }
        reAjax(regData, function (res) {
          if (res.code == 0) {
            layer.msg('注册成功');
          } else {
            layer.msg(res.msg);
          }
        });


      });


      function yzAccount(obj) {
        var dtd = $.Deferred();
        reAjax({
          Command: 'CheckUserName',
          UserName_c: $.trim($(obj).val())
        }, function (res) {
          if (res.IsExist >= 1) {
            dtd.reject(res); //存在
          } else {
            dtd.resolve(res); //不存在
          }
        });
        return dtd.promise();
      }
      function daoTime(sec) {
        Timer = setInterval(function () {
          if (iNum > 0) {
            iNum--;
            $('#yzBtn').html(iNum + 's');

          } else {
            clearInterval(Timer);
            $('#yzBtn').html('获取验证码');
            iNum = sec;
          }
        }, 1000);

      }

    })


  </script>
</body>

</html>